package com.edu.dao.impl;

import com.edu.bean.Book;
import com.edu.dao.BaseDao;
import com.edu.dao.BookDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BookDaoImpl implements BookDao {
    public List<Book> selectAllBook() {
        String sql="select * from book";
        Connection conn= BaseDao.getConn();//打开连接
        PreparedStatement ps= null;
        ResultSet rs=null;
        try {
            ps= conn.prepareStatement(sql);
            rs = ps.executeQuery();
            List<Book> lb=new ArrayList<Book>();
            while(rs.next()) {
                Book bk=new Book();
                bk.setBookId(rs.getInt("bookId"));
                bk.setBookName(rs.getString("bookName"));
                bk.setBookType(rs.getString("bookType"));
                bk.setBookAuthor(rs.getString("bookAuthor"));
            }
            return  lb;
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            BaseDao.closeAll(conn, ps,rs);
        }

        return null;
    }
}
